using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace XNAStuding
{

    /// <summary>
    /// Class to handle all the start scene variables 
    /// </summary>
    public class StartScene : Microsoft.Xna.Framework.DrawableGameComponent
    {
        bool AboutTex = false;
        Rectangle freefalling = new Rectangle(271, 236, 249, 47);
        Rectangle InclineEXP = new Rectangle(160, 391, 453, 51);
        Rectangle PhysicalPendulum = new Rectangle(204, 309, 375, 55);
        Rectangle Home = new Rectangle(26, 14, 26, 26);
        Rectangle About = new Rectangle(648, 478, 126, 94);
        Rectangle exit = new Rectangle(331, 472, 107, 43);
        Rectangle Return = new Rectangle(325, 533, 75, 29);
        
        bool exp1 = false;
        bool exp2 = false; 
        bool exp3 = false; 
        bool ex = false;
        public static bool started;
        /// <summary>
        /// Constarctor of the class
        /// </summary>
        /// <param name="game"></param>
        public StartScene(Game game): base(game)
        {
        }
        protected override void LoadContent()
        {
            
            base.LoadContent();
        }
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
        }
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            MouseState mouse_state = Mouse.GetState();
            Rectangle mouseRec = new Rectangle((int)mouse_state.X, (int)mouse_state.Y, 1, 1);
            exp1 = false; exp2 = false; exp3 = false; ex = false;
            KeyboardState keyboardState = Keyboard.GetState();

            if (mouseRec.Intersects(freefalling) && !started && !AboutTex)
            { 
                exp1 = true;
                if (mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                { started = true; Game1.Experiment_No = 1; Game1.load(); }
            }
            if (mouseRec.Intersects(PhysicalPendulum) && !started && !AboutTex)
            { 
                exp2 = true;
                if (mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                { started = true; Game1.Experiment_No = 2; Game1.load(); } 
            }
            if (mouseRec.Intersects(InclineEXP) && !started && !AboutTex)
            { 
                exp3 = true;
                if (mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                { started = true; Game1.Experiment_No = 3; Game1.load(); }
            }
            if ((mouseRec.Intersects(Home) && mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed || keyboardState.IsKeyDown(Keys.Escape) )&& started && !AboutTex && !Globals.t.go)
            { 
                started = false; Game1.Experiment_No = 0; Game1.ClearComponants(); Game1.load(); 
            }
            if (((mouseRec.Intersects(About) && mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed ) || keyboardState.IsKeyDown(Keys.F1)) && !AboutTex && !started)
            { 
                started = true; AboutTex = true; Game1.Experiment_No = 0;  
            }
            if (((mouseRec.Intersects(Return) && mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed )||keyboardState.IsKeyDown(Keys.Escape))&& AboutTex)
            {
                started = false; AboutTex = false; 
            }
            if (mouseRec.Intersects(exit) && !started && !AboutTex)
            {
                ex = true; 
                if(mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                    Globals.game.Exit();
            }
                
            base.Update(gameTime);
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Draw(GameTime gameTime)
        {
            Globals.spritePatch.Begin();
            if (!started)
                Globals.spritePatch.Draw(Game1.startscene, new Vector2(0,0), Color.White);
            if (!started && exp1)
                Globals.spritePatch.Draw(Game1.startscene, new Rectangle(271, 236, 249, 47), new Rectangle(929, 235, 249, 47), Color.White);
            if (!started && exp2)
                Globals.spritePatch.Draw(Game1.startscene, new Rectangle(191, 311, 399, 47), new Rectangle(853, 312, 400, 47), Color.White);
            if (!started && exp3)
                Globals.spritePatch.Draw(Game1.startscene, new Rectangle(142, 390, 490, 51), new Rectangle(810, 391, 490, 51), Color.White);
            if (!started && ex)
                Globals.spritePatch.Draw(Game1.startscene, new Rectangle(130, 469, 490, 51), new Rectangle(810, 472, 490, 51), Color.White);
            if (started && AboutTex)
                Globals.spritePatch.Draw(Game1.AboutUs, new Vector2(0,0), Color.White);
            Globals.spritePatch.End();
            base.Draw(gameTime);
        }

    }
}